package com.example.personalinfo;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.databinding.BindingAdapter;

import com.squareup.picasso.Picasso;

/**
 * author: liliang
 * date: 2020/10/20 9:13 PM
 */
public class ImageViewBindingAdapter {

    @BindingAdapter(value = {"image", "defaultImageResource"},
            requireAll = false)
    public static void setImage(ImageView imageView, String imageUrl,
                                int imageResource) {
        if (!TextUtils.isEmpty(imageUrl)) {
            Picasso.get()
                    .load(imageUrl)
                    .placeholder(R.drawable.ic_launcher_background)
                    .error(R.drawable.ic_launcher_foreground)
                    .into(imageView);
        } else {
            imageView.setImageResource(imageResource);
        }
    }
}
